﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using PLC.Domain.Entity;

namespace PLC.Infrastructure.DbContext.Config;

public class BarcodeDataConfig:IEntityTypeConfiguration<BarcodeData>
{
    public void Configure(EntityTypeBuilder<BarcodeData> builder)
    {
        // 表明
        builder.ToTable("tb_data_barcode");
        // 创建索引
        builder.HasIndex(p => new { p.LowerEndPlateCode, p.UpperEndPlateCode });
        // 设置主键
        builder.HasKey(p => p.Id);
        // 主键不自增
        builder.Property(p => p.Id).ValueGeneratedNever();
        builder.Property(p => p.LowerEndPlateCode).IsRequired().HasMaxLength(64).HasDefaultValue("");
        builder.Property(p => p.UpperEndPlateCode).IsRequired().HasMaxLength(64).HasDefaultValue("");
        builder.Property(p => p.MembraneElectrode).IsRequired().HasMaxLength(64).HasDefaultValue("");
        builder.Property(p => p.BipolarPlate).IsRequired().HasMaxLength(64).HasDefaultValue("");
    }
}